Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

has-value

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

has-value

Returns true if a value exists, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays. Other libs do this, but I needed one that would optionally _not_ treat zero as empty. Also, this works with booleans and other valu

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30M
increased by13.49%
Maintainers
1
Weekly downloads
 
Created

What is has-value?

The has-value npm package is used to check if a value exists, is not empty, or is not undefined. It is useful for validating data and ensuring that required fields are populated.

What are has-value's main functionalities?

Check if a value exists

This feature checks if a given value exists. In this example, the string 'Hello World' is checked, and since it is a non-empty string, the result is true.

const hasValue = require('has-value');
console.log(hasValue('Hello World')); // true

Check if an object property has a value

This feature checks if a specific property of an object has a value. In this example, the object has a property 'name' with a value 'John Doe', so the result is true.

const hasValue = require('has-value');
const obj = { name: 'John Doe' };
console.log(hasValue(obj, 'name')); // true

Check if an array has a value

This feature checks if an array has any values. In this example, the array [1, 2, 3] is checked, and since it contains elements, the result is true.

const hasValue = require('has-value');
const arr = [1, 2, 3];
console.log(hasValue(arr)); // true

Check if a nested object property has a value

This feature checks if a nested property within an object has a value. In this example, the nested property 'user.name' is checked, and since it has a value 'Jane Doe', the result is true.

const hasValue = require('has-value');
const nestedObj = { user: { name: 'Jane Doe' } };
console.log(hasValue(nestedObj, 'user.name')); // true

Other packages similar to has-value

Keywords

FAQs

Package last updated on 22 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc